package damngoodcoffee.smart.commands;

import java.util.List;
import java.util.logging.Logger;

import damngoodcoffee.smart.Parser;
import damngoodcoffee.smart.ParserException;

public class ParseCommand implements Command {
    private static Logger logger = Logger.getLogger(ParseCommand.class
	    .getCanonicalName());
    private String file;
    private Parser parser;

    public ParseCommand(Parser parser, String file) {
	this.file = file;
	this.parser = parser;
    }

    public void execute() throws CommandException {
	try {
	    List<Command> commands = parser.parse(file);
	    for (Command command : commands) {
		command.execute();
	    }
	} catch (ParserException e) {
	    throw new CommandException(e);
	}
    }

    public String toString() {
	return "ParseCommand: " + file;
    }
}
